<?php
/**
 *
 *
 *
 */
namespace Yz\modules\Users;
use Yz_String,
    TypeError,
    ValueError
;
class Item_User
    extends \Yz_Item_Abstract
{


    /*************************
     *      Public methods   *
     *************************/

    /**
     *  @param string
     *  @return this
     *  @throw TypeError
     *  @throw ValueError
     */
    public function verifyPassword($password)
    {
        if (! is_string($password))
            throw TypeError::_new_();
        if ("" === $password)
            throw ValueError::_new_();
        return $this->matchPassword($password);
    }

    /**
     *      Allow empty string or not ?
     *  @param string
     *  @return this
     *  @throw TypeError
     *  @throw ValueError
     */
    public function setPassword($password)
    {
        if (! is_string($password))
            throw TypeError::_new_();
        if ("" === $password)
            throw ValueError::_new_();
        $this->__dict__['passwordMD5'] = md5($password);
        return $this;
    }


    /**
     *
     */
    protected function matchPassword($password)
    {
        return md5($password) === $this->__dict__['passwordMD5'];
    }

} // class
